﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace SCS.DAL
{
	/// <summary>
	/// 数据访问类:SCS_Charging_Standard_Audit
	/// </summary>
	public partial class SCS_Charging_Standard_Audit
	{
		public SCS_Charging_Standard_Audit()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(SCS.Model.SCS_Charging_Standard_Audit model)
		{
			StringBuilder strSql=new StringBuilder();
			StringBuilder strSql1=new StringBuilder();
			StringBuilder strSql2=new StringBuilder();
			if (model.Standard_TimeStamp != null)
			{
				strSql1.Append("Standard_TimeStamp,");
				strSql2.Append("'"+model.Standard_TimeStamp+"',");
			}
			if (model.Standard_ID != null)
			{
				strSql1.Append("Standard_ID,");
				strSql2.Append(""+model.Standard_ID+",");
			}
			if (model.Charge_Year != null)
			{
				strSql1.Append("Charge_Year,");
				strSql2.Append("'"+model.Charge_Year+"',");
			}
			if (model.Grade_ID != null)
			{
				strSql1.Append("Grade_ID,");
				strSql2.Append("'"+model.Grade_ID+"',");
			}
			if (model.Class_Name != null)
			{
				strSql1.Append("Class_Name,");
				strSql2.Append("'"+model.Class_Name+"',");
			}
			if (model.Class_ID != null)
			{
				strSql1.Append("Class_ID,");
				strSql2.Append("'"+model.Class_ID+"',");
			}
			if (model.Specialty_ID != null)
			{
				strSql1.Append("Specialty_ID,");
				strSql2.Append("'"+model.Specialty_ID+"',");
			}
			if (model.Standard_Description != null)
			{
				strSql1.Append("Standard_Description,");
				strSql2.Append("'"+model.Standard_Description+"',");
			}
			if (model.Standard_Big_Category_ID != null)
			{
				strSql1.Append("Standard_Big_Category_ID,");
				strSql2.Append(""+model.Standard_Big_Category_ID+",");
			}
			if (model.Standard_Small_Category_ID != null)
			{
				strSql1.Append("Standard_Small_Category_ID,");
				strSql2.Append(""+model.Standard_Small_Category_ID+",");
			}
			if (model.Standard_Amount != null)
			{
				strSql1.Append("Standard_Amount,");
				strSql2.Append("'"+model.Standard_Amount+"',");
			}
			if (model.Standard_IsEnable != null)
			{
				strSql1.Append("Standard_IsEnable,");
				strSql2.Append(""+model.Standard_IsEnable+",");
			}
			if (model.Updated_Date != null)
			{
				strSql1.Append("Updated_Date,");
				strSql2.Append("'"+model.Updated_Date+"',");
			}
			if (model.Updated_By != null)
			{
				strSql1.Append("Updated_By,");
				strSql2.Append("'"+model.Updated_By+"',");
			}
			if (model.Log_ID != null)
			{
				strSql1.Append("Log_ID,");
				strSql2.Append(""+model.Log_ID+",");
			}
			strSql.Append("insert into SCS_Charging_Standard_Audit(");
			strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
			strSql.Append(")");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(SCS.Model.SCS_Charging_Standard_Audit model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update SCS_Charging_Standard_Audit set ");
			if (model.Standard_TimeStamp != null)
			{
				strSql.Append("Standard_TimeStamp='"+model.Standard_TimeStamp+"',");
			}
			else
			{
				strSql.Append("Standard_TimeStamp= null ,");
			}
			if (model.Standard_ID != null)
			{
				strSql.Append("Standard_ID="+model.Standard_ID+",");
			}
			else
			{
				strSql.Append("Standard_ID= null ,");
			}
			if (model.Charge_Year != null)
			{
				strSql.Append("Charge_Year='"+model.Charge_Year+"',");
			}
			else
			{
				strSql.Append("Charge_Year= null ,");
			}
			if (model.Grade_ID != null)
			{
				strSql.Append("Grade_ID='"+model.Grade_ID+"',");
			}
			else
			{
				strSql.Append("Grade_ID= null ,");
			}
			if (model.Class_Name != null)
			{
				strSql.Append("Class_Name='"+model.Class_Name+"',");
			}
			else
			{
				strSql.Append("Class_Name= null ,");
			}
			if (model.Class_ID != null)
			{
				strSql.Append("Class_ID='"+model.Class_ID+"',");
			}
			else
			{
				strSql.Append("Class_ID= null ,");
			}
			if (model.Specialty_ID != null)
			{
				strSql.Append("Specialty_ID='"+model.Specialty_ID+"',");
			}
			else
			{
				strSql.Append("Specialty_ID= null ,");
			}
			if (model.Standard_Description != null)
			{
				strSql.Append("Standard_Description='"+model.Standard_Description+"',");
			}
			else
			{
				strSql.Append("Standard_Description= null ,");
			}
			if (model.Standard_Big_Category_ID != null)
			{
				strSql.Append("Standard_Big_Category_ID="+model.Standard_Big_Category_ID+",");
			}
			else
			{
				strSql.Append("Standard_Big_Category_ID= null ,");
			}
			if (model.Standard_Small_Category_ID != null)
			{
				strSql.Append("Standard_Small_Category_ID="+model.Standard_Small_Category_ID+",");
			}
			else
			{
				strSql.Append("Standard_Small_Category_ID= null ,");
			}
			if (model.Standard_Amount != null)
			{
				strSql.Append("Standard_Amount='"+model.Standard_Amount+"',");
			}
			else
			{
				strSql.Append("Standard_Amount= null ,");
			}
			if (model.Standard_IsEnable != null)
			{
				strSql.Append("Standard_IsEnable="+model.Standard_IsEnable+",");
			}
			else
			{
				strSql.Append("Standard_IsEnable= null ,");
			}
			if (model.Updated_Date != null)
			{
				strSql.Append("Updated_Date='"+model.Updated_Date+"',");
			}
			else
			{
				strSql.Append("Updated_Date= null ,");
			}
			if (model.Updated_By != null)
			{
				strSql.Append("Updated_By='"+model.Updated_By+"',");
			}
			else
			{
				strSql.Append("Updated_By= null ,");
			}
			if (model.Log_ID != null)
			{
				strSql.Append("Log_ID="+model.Log_ID+",");
			}
			else
			{
				strSql.Append("Log_ID= null ,");
			}
			int n = strSql.ToString().LastIndexOf(",");
			strSql.Remove(n, 1);
			strSql.Append(" where ");
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from SCS_Charging_Standard_Audit ");
			strSql.Append(" where " );
			int rowsAffected=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.SCS_Charging_Standard_Audit GetModel()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1  ");
			strSql.Append(" Standard_TimeStamp,Standard_ID,Charge_Year,Grade_ID,Class_Name,Class_ID,Specialty_ID,Standard_Description,Standard_Big_Category_ID,Standard_Small_Category_ID,Standard_Amount,Standard_IsEnable,Updated_Date,Updated_By,Log_ID ");
			strSql.Append(" from SCS_Charging_Standard_Audit ");
			strSql.Append(" where " );
			SCS.Model.SCS_Charging_Standard_Audit model=new SCS.Model.SCS_Charging_Standard_Audit();
			DataSet ds=DbHelperSQL.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public SCS.Model.SCS_Charging_Standard_Audit DataRowToModel(DataRow row)
		{
			SCS.Model.SCS_Charging_Standard_Audit model=new SCS.Model.SCS_Charging_Standard_Audit();
			if (row != null)
			{
				if(row["Standard_TimeStamp"]!=null && row["Standard_TimeStamp"].ToString()!="")
				{
					model.Standard_TimeStamp=DateTime.Parse(row["Standard_TimeStamp"].ToString());
				}
				if(row["Standard_ID"]!=null && row["Standard_ID"].ToString()!="")
				{
					model.Standard_ID=int.Parse(row["Standard_ID"].ToString());
				}
				if(row["Charge_Year"]!=null)
				{
					model.Charge_Year=row["Charge_Year"].ToString();
				}
				if(row["Grade_ID"]!=null)
				{
					model.Grade_ID=row["Grade_ID"].ToString();
				}
				if(row["Class_Name"]!=null)
				{
					model.Class_Name=row["Class_Name"].ToString();
				}
				if(row["Class_ID"]!=null)
				{
					model.Class_ID=row["Class_ID"].ToString();
				}
				if(row["Specialty_ID"]!=null)
				{
					model.Specialty_ID=row["Specialty_ID"].ToString();
				}
				if(row["Standard_Description"]!=null)
				{
					model.Standard_Description=row["Standard_Description"].ToString();
				}
				if(row["Standard_Big_Category_ID"]!=null && row["Standard_Big_Category_ID"].ToString()!="")
				{
					model.Standard_Big_Category_ID=int.Parse(row["Standard_Big_Category_ID"].ToString());
				}
				if(row["Standard_Small_Category_ID"]!=null && row["Standard_Small_Category_ID"].ToString()!="")
				{
					model.Standard_Small_Category_ID=int.Parse(row["Standard_Small_Category_ID"].ToString());
				}
				if(row["Standard_Amount"]!=null)
				{
					model.Standard_Amount=row["Standard_Amount"].ToString();
				}
				if(row["Standard_IsEnable"]!=null && row["Standard_IsEnable"].ToString()!="")
				{
					model.Standard_IsEnable=int.Parse(row["Standard_IsEnable"].ToString());
				}
				if(row["Updated_Date"]!=null && row["Updated_Date"].ToString()!="")
				{
					model.Updated_Date=DateTime.Parse(row["Updated_Date"].ToString());
				}
				if(row["Updated_By"]!=null)
				{
					model.Updated_By=row["Updated_By"].ToString();
				}
				if(row["Log_ID"]!=null && row["Log_ID"].ToString()!="")
				{
					model.Log_ID=int.Parse(row["Log_ID"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select Standard_TimeStamp,Standard_ID,Charge_Year,Grade_ID,Class_Name,Class_ID,Specialty_ID,Standard_Description,Standard_Big_Category_ID,Standard_Small_Category_ID,Standard_Amount,Standard_IsEnable,Updated_Date,Updated_By,Log_ID ");
			strSql.Append(" FROM SCS_Charging_Standard_Audit ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" Standard_TimeStamp,Standard_ID,Charge_Year,Grade_ID,Class_Name,Class_ID,Specialty_ID,Standard_Description,Standard_Big_Category_ID,Standard_Small_Category_ID,Standard_Amount,Standard_IsEnable,Updated_Date,Updated_By,Log_ID ");
			strSql.Append(" FROM SCS_Charging_Standard_Audit ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM SCS_Charging_Standard_Audit ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.Standard_ID desc");
			}
			strSql.Append(")AS Row, T.*  from SCS_Charging_Standard_Audit T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		*/

		#endregion  Method
		#region  MethodEx

		#endregion  MethodEx
	}
}

